// pages/buyshop-detail/buyshop-detail.js
import { Shop } from '../../models/shop'
import { Publish } from '../../models/other'
import collectFun from '../../util/collect'
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'
const shopModel = new Shop()
const publishModel = new Publish()
import Call from '../../util/call'
import queryParams from '../../util/query'

const app = getApp()
Page({
  data: {
    data: {},
    id: '',
    isIphoneX: app.globalData.isIPhoneX,
    showBackHome: false
  },

  onLoad (options) {
    wx.showLoading({
      title: '加载中'
    })
    this.setData({
      id: options.id || queryParams(decodeURIComponent(options.q), 'id'),
      showBackHome: !!options.ald_share_src
    })
    this.getDetail()
  },


  getDetail () {
    shopModel.buyShopDetail({
      id: this.data.id
    }, res => {
      if (res.auditStatus == 0) {
        // setTimeout(() => {
        //   Notify({
        //     message: '正在审核中，请耐心等待回复！',
        //     duration: 30000,
        //     background: '#46E3BC'
        //   })
        // }, 1000)
        Dialog.alert({
          message: '正在审核中，请耐心等待回复！',
        }).then(() => {
          // on close
        })
      }
      wx.hideLoading()
      this.setData({
        data: res
      })
    })
  },


  onCollect() {
    collectFun('买店', this.data.data.id, this.data.data.collectState, () => {
      this.setData({
        'data.collectState': !this.data.data.collectState
      })
    })
  },

  call () {
    Call(this.data.id, '买店')
    // wx.requestSubscribeMessage({
    //   tmplIds: ['6E4h4hY0mRpdOPOZLZj6EGV26CKx-3BoSJ3wwLcs3t4', 'gqiUsZicpSK12MajZO_xtLfDLXEjyvcTp51cs7GsqoY', '-DHKrW9DRvbg3sEoVRYtcV92AWETa-B9VW8Wst3WgMg'],
    // })
  },

  onReady () {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    publishModel.shareStick({
      contentId: this.data.id,
      type: '买店'
    })
    return {
      title: '买店' + this.data.data.title,
      path: `/pages/buyshop-detail/buyshop-detail?id=${this.data.id}&otherId=${wx.getStorageSync('userInfo').user_id}&time=${+new Date()}`
    }
  }
})
